classdef Approximation < handle
    
    properties
        filterType = '';
        filterName = '';
        gain = 0;
        Fp = 0;
        Fa = 0;
        Ap = 0;
        Aa = 0;
        DenormType = '';
        DenormVal = 0;
        fixOrder = false;
        order = 0;
        maxOrder = 0;
        maxQ = 0; % 0 -> No max Q
        show = true;
        colorNum = 0;
        Delay = 0;
        Tolerance = 0;
        Trans = 0;
        
        filterCalc;
    end

    methods
        
        function this = Approximation(filterType, filterName, gain, Fp, Fa, Ap, Aa, DenormType, DenormVal, fixOrder, order, maxQ, Delay, Tolerance, Trans)
            this.filterType = filterType;
            this.filterName = filterName;
            this.gain = gain;
            this.Ap = Ap;
            this.Aa = Aa;
            this.Fp = Fp;
            this.Fa = Fa;
            this.DenormType = DenormType;
            this.DenormVal = DenormVal;
            this.fixOrder = fixOrder;
            this.Trans = Trans;
            if fixOrder
                this.order = order;
            else
                this.order = 0;
            end            
            this.maxQ = maxQ;
            this.Delay = Delay;
            this.Tolerance = Tolerance;
            this.filterCalc = callAprox(this);
            this.order = this.filterCalc.Order;
            this.filterCalc.calcQ();
           
            while ( (this.maxQ~=0) && (fixOrder==false) &&...
                    (max(this.filterCalc.Q)>this.maxQ) &&...
                    (this.filterCalc.Order>1) )
                this.order = this.filterCalc.Order-1;
                this.filterCalc = callAprox(this);
                this.filterCalc.calcQ();
            end
            if this.filterCalc.Order <= 25
                this.filterCalc.calcTimeDataNoLim();
                this.filterCalc.calcQ();
            end
        end
        
        function filterCalc = callAprox(this)
            
            switch this.filterName
                case 'Butterworth'
                    filterCalc = Butterworth(this);
                case 'Chebyshev I'
                    filterCalc = Chebyshev1(this);
                case 'Chebyshev II'
                    filterCalc = Chebyshev2(this);
                case 'Legendre'
                    filterCalc = Legendre(this);
                case 'Cauer'
                    filterCalc = Cauer(this);
                case 'Bessel'
                    filterCalc = Bessel(this);
                case 'Gauss'
                    filterCalc = Gauss(this);
                case 'Better' 
                    filterCalc = TransBetter(this);
                case 'Letter'
                    filterCalc = TransLetter(this);
                case 'Buby'
                    filterCalc = TransBuby(this);
            end
        end
    end
end